# -*- mode: python; -*-

#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

setup_sources = [
    'setup.py',
    'requirements.txt',
    'run_tests.sh',
    'test-requirements.txt',
    '.testr.conf',
    '.coveragerc',
    'MANIFEST.in',
]

setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(
        env.Install(Dir('.'), "#controller/src/container/kube-manager/" + file))

local_sources = [
    'kube_manager/__init__.py',
    'kube_manager/kube_manager.py',
    'kube_manager/common/__init__.py',
    'kube_manager/common/logger.py',
    'kube_manager/common/args.py',
    'kube_manager/common/kube_config_db.py',
    'kube_manager/common/utils.py',
    'kube_manager/kube/__init__.py',
    'kube_manager/kube/kube_monitor.py',
    'kube_manager/kube/namespace_monitor.py',
    'kube_manager/kube/network_policy_monitor.py',
    'kube_manager/kube/pod_monitor.py',
    'kube_manager/kube/service_monitor.py',
    'kube_manager/kube/endpoint_monitor.py',
    'kube_manager/kube/ingress_monitor.py',
    'kube_manager/kube/network_monitor.py',
    'kube_manager/vnc/__init__.py',
    'kube_manager/vnc/config_db.py',
    'kube_manager/vnc/db.py',
    'kube_manager/vnc/label_cache.py',
    'kube_manager/vnc/reaction_map.py',
    'kube_manager/vnc/vnc_kubernetes.py',
    'kube_manager/vnc/vnc_kubernetes_config.py',
    'kube_manager/vnc/vnc_common.py',
    'kube_manager/vnc/vnc_namespace.py',
    'kube_manager/vnc/vnc_network_policy.py',
    'kube_manager/vnc/vnc_security_policy.py',
    'kube_manager/vnc/vnc_pod.py',
    'kube_manager/vnc/vnc_service.py',
    'kube_manager/vnc/vnc_endpoints.py',
    'kube_manager/vnc/vnc_ingress.py',
    'kube_manager/vnc/loadbalancer.py',
    'kube_manager/vnc/link_local_manager.py',
    'kube_manager/vnc/flow_aging_manager.py',
    'kube_manager/vnc/vnc_tags.py',
    'kube_manager/vnc/vnc_network.py',
    'kube_manager/tests/__init__.py',
    'kube_manager/tests/vnc/__init__.py',
    'kube_manager/tests/vnc/db_mock.py',
    'kube_manager/tests/vnc/test_case.py',
    'kube_manager/tests/vnc/test_config_db.py',
    'kube_manager/tests/vnc/test_vnc_endpoints.py',
    'kube_manager/tests/vnc/test_vnc_ingress.py',
    'kube_manager/tests/vnc/test_vnc_kubernetes.py',
    'kube_manager/tests/vnc/test_vnc_namespace.py',
    'kube_manager/tests/vnc/test_vnc_pod.py',
    'kube_manager/tests/vnc/test_vnc_service.py',
    'kube_manager/tests/vnc/test_vnc_network_policy.py',
    'kube_manager/tests/vnc/vnc_api_mock.py',
    'kube_manager/tests/kube/__init__.py',
    'kube_manager/tests/kube/test_kube_monitor.py',
]

# Sandesh source files.
sandesh_sources = []
sandesh_sources += env.SandeshGenPy('kube_manager.sandesh',
                                    'kube_manager/sandesh/', False)
sandesh_sources += env.SandeshGenPy('kube_introspect.sandesh',
                                    'kube_manager/sandesh/', False)

local_sources_rules = []
for file in local_sources:
    target = "/".join(file.split('/')[:-1])
    local_sources_rules.append(
        env.Install(target, "#controller/src/container/kube-manager/" + file))

# Documentation
doc_files = []
doc_files += env.SandeshGenDoc('kube_manager.sandesh')
doc_files += env.SandeshGenDoc('kube_introspect.sandesh')

cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_depends = []
sdist_depends.extend(setup_sources_rules)
sdist_depends.extend(local_sources_rules)
sdist_depends.extend(sandesh_sources)
sdist_gen = env.Command('dist/kube_manager-0.1dev.tar.gz', 'setup.py',
                        cd_cmd + 'python setup.py sdist')

env.Depends(sdist_gen, sdist_depends)
env.Default(sdist_gen)

if 'install' in BUILD_TARGETS:
    install_cmd = env.Command(None, 'setup.py',
                              cd_cmd + 'python setup.py install %s' %
                              env['PYTHON_INSTALL_OPT'])
    env.Depends(install_cmd, sdist_depends)
    env.Alias('install', install_cmd)

env.SetupPyTestSuite(sdist_gen,
                     '/config/api-server/dist/contrail-api-server-0.1dev.tar.gz',
                     '/../noarch/config/svc-monitor/dist/svc_monitor-0.1dev.tar.gz')

env.Alias('install', env.Install(
    env['INSTALL_MESSAGE_DOC'] + '/contrail-kube-manager/', doc_files))

env.Alias('install', env.Install(env['INSTALL_CONF'],
    'supervisord_kubernetes.conf'))
env.Alias('install', env.Install(env['INSTALL_CONF'] +
    '/supervisord_kubernetes_files', 'contrail-kube-manager.ini'))
env.Alias('install', env.InstallAs(env['INSTALL_INITD'] +
    '/contrail-kube-manager', 'contrail-kube-manager.initd.supervisord'))

env.Alias('install', env.InstallAs(env['INSTALL_SYSTEMD'] +
          '/contrail-kube-manager.service', 'systemd/contrail-kube-manager.service'))

# Local Variables:
# mode: python
# End:
